package com.web.controller.lxf;

import com.core.dto.*;
import com.web.controller.AbstractController;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: lxf
 * Date: 2017/8/21
 * Time: 10:46
 * To change this template use Editor | File and Code Templates.
 */
@RestController
@RequestMapping("/huawei")
public class HuaweiTestController extends AbstractController {

    private static final Logger LOGGER = LoggerFactory.getLogger(AbstractController.class);

    @RequestMapping(value = "appraise/{status}", method = RequestMethod.POST)
    public HuaweiOutDTO appraise(@PathVariable String status, @RequestBody HuaweiAppraiseDTO huaweiDTO) {
        LOGGER.debug("TraceId is {},sn = " + huaweiDTO.getSN());
        HuaweiOutDTO huaweiOutDTO = new HuaweiOutDTO(status, "200", "");
        return huaweiOutDTO;
    }

    @RequestMapping(value = "incidentHandle/{status}", method = RequestMethod.POST)
    public HuaweiOutDTO incidentHandle(@PathVariable String status, @RequestBody HuaweiIncidentHandleDTO huaweiDTO) {
        System.out.println("HuaweiIncidentHandleDTO = " + huaweiDTO.toString());
        HuaweiOutDTO huaweiOutDTO = new HuaweiOutDTO(status, "errorMsg");
        return huaweiOutDTO;
    }

    @RequestMapping(value = "findContact/{count}", method = RequestMethod.POST)
    public List<HuaweiContactDTO> findContact(@PathVariable String count, @RequestBody HuaweiQueryContactDTO huaweiDTO) {
        System.out.println("HuaweiQueryContactDTO = " + huaweiDTO.toString());
        if ("99".equals(count)) {
            return null;
        }
        int index = Integer.parseInt(count);
        List<HuaweiContactDTO> list = new ArrayList<>();
        for (int i = 0; i < index; i++) {
            HuaweiContactDTO dto = new HuaweiContactDTO("1", "name", "18682664521", "4", "741852@qq.com", "6", "都是阿斯蒂芬", "8", "NA");
            list.add(dto);
        }
        return list;
    }

    @RequestMapping(value = "createTicket/{status}/{incidengNum}", method = RequestMethod.POST)
    public HuaweiOutDTO createTicket(@PathVariable String status, @PathVariable String incidengNum, @RequestBody HuaweiCreateTicketDTO huaweiDTO) {
        System.out.println("HuaweiCreateTicketDTO = " + huaweiDTO.toString());
        HuaweiOutDTO outDTO = new HuaweiOutDTO();
        outDTO.setReturnStatus(status);
        outDTO.setMsgData("alkfjvnsaf");
        outDTO.setIncidentNumber(incidengNum);
        return outDTO;
    }

    @RequestMapping(value = "incidentQuery/{operator}/{product}/{status}", method = RequestMethod.POST)
    public HuaweiOutDTO incidentQuery(@PathVariable String operator, @PathVariable String product, @PathVariable String status, @RequestBody HuaweiIncidentQueryDTO huaweiDTO) {
        System.out.println("HuaweiIncidentQueryDTO = " + huaweiDTO.toString());
//        String status = "Closed1";
        if ("123".equals(operator)) {
            return null;
        }
        String type = "CS-Technical Request";
        HuaweiOutDTO outDTO = new HuaweiOutDTO(huaweiDTO.getIncidentNumber(), "http://www.baidu.com", "sdlfkjvjik", product, operator, status, type, "subType");
        return outDTO;
    }


}
